package com.limao.CacheManager;

import com.Hazelcast.Cache;
import com.Hazelcast.CacheFactory;
import com.limao.DBDataClass.SysRedbagClass;
import com.limao.DBProvider.SysRedbagProvider;
import com.limao.cache.BasicModule;

public class SysRedbagCache extends BasicModule{

	private SysRedbagProvider provider;
	private static SysRedbagCache instance;
    
    public static SysRedbagCache getInstance() {
        return instance;
    }

    private Cache<String, SysRedbagClass> sysRedbagCache;


    public SysRedbagCache() {
    	super("SysRedbagCache");
    	sysRedbagCache = CacheFactory.createCache("cd_SysRedbagCache");
		initProvider();

    }
    
    @Override
	public void initialize() {
        super.initialize();
        instance=this;
    }
    
    public void ClearObjectCache()
    {
		if(sysRedbagCache.size()>0)
		{
			sysRedbagCache.clear();
		}

    } 
    
	public SysRedbagClass Load_SysRedbagByid(int redbagid)
	{
		SysRedbagClass obj=sysRedbagCache.get(redbagid+"");
		if(obj==null)
		{
			obj=provider.Load_SysRedbagByid(redbagid);
			if(obj!=null)
			{
				sysRedbagCache.put(redbagid+"", obj);
			}
		}
		return obj;
	}	
	
	
	
	private void initProvider() {
		if (provider == null) {
			try {
				provider = SysRedbagProvider.getInstance();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	

}
